﻿using System;
using System.Reflection;
using LaserTag.Module.AForgeModule.Controllers;
using LaserTag.Module.AForgeModule.Services;
using LaserTag.Module.AForgeModule.ViewModels;
using LaserTag.Module.AForgeModule.Views;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Unity;

namespace LaserTag.Module.AForgeModule
{
    /// <summary>
    /// The AForgeModule is a composite component.  It handles
    /// applications duties related to the AForge library
    /// </summary>
    public class AForgeModule : IModule
    {
        private readonly IUnityContainer m_container;

        /// <summary>
        /// This module is instantiated via Prism using dependency injection,
        /// so you will not find any instances of "var module = new AForgeModule"
        /// </summary>
        /// <param name="container">The dependency injection container</param>
        public AForgeModule(IUnityContainer container)
        {
            /* Keep reference to our dependency injection container for later use */
            m_container = container;
        }

        #region IModule Members

        /// <summary>
        /// Initializes the AForgeModule.  This is called automatically by Prism
        /// </summary>
        public void Initialize()
        {
            m_container.RegisterType<IHslConfiguration, HslConfiguration>();

            /* Here we register an interface type, and its concrete class definition.  This allows the dependency
             * injection to resolve the concrete class when it finds a class requests the interface type */
            m_container.RegisterType<IAForgeVideoProcessorSetupViewModel, AForgeVideoProcessorSetupViewModel>();
            m_container.RegisterType<IAForgeVideoProcessorSetupView, AForgeVideoProcessorSetupView>();

            /* By resolving the AForgeVideoProcessorController type, it allows the dependency injector to 
             * inject any dependencies that AForgeVideoProcessorController may want.  Look in the constructor
             * of AForgeVideoProcessorController to see what types it is requesting */
            m_container.Resolve<AForgeVideoProcessorController>().Run();
        }

        #endregion
    }
}
